package com.aiit.carinsurance2.controller;

import com.aiit.carinsurance2.pojo.Insured;
import com.aiit.carinsurance2.pojo.User;
import com.aiit.carinsurance2.service.InsuredService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class InsuredController {
    @Autowired
    private InsuredService insuredService;

    @GetMapping("/insured")
    public String getinsured(){
        return "insured";
    }

    @PostMapping("/insured")
    public String postinsured(Insured insured, HttpSession session){
        Object obj=session.getAttribute("user");

        User user =(User) obj;
        System.out.println(user);
        int id=((User) obj).getUid();
        //car.setUid(id);
        insured.setUid(id);
        int rlt=insuredService.addinsured(insured);
        return "personal";
    }
}
